package actions;

import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.StudentModel;

import org.apache.struts.action.*;

import db.DbException;

import forms.StudentsForm;

public class MyApplicationAction extends Action 
{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		String userName = request.getUserPrincipal().getName();
		
		try {
			boolean userHasApp = StudentModel.userHasApplication(userName);
			
			if (userHasApp == true) {
				HashMap application = StudentModel.getApplicationByUser(userName);
				
				request.getSession().setAttribute("application", application);
								
				return mapping.findForward("appsuccess");
			}
			
		} catch (DbException ex) {
			ex.printStackTrace();
		}
	
		return mapping.findForward("noappsuccess");
	}
}
